'''
Created on 07/06/2010

@author: Will
'''
from pyglet.gl import *
from pyglet import font,clock
from pyglet.graphics import Batch

class Hud(object):

    def __init__(self, win,cam):
        self.win = win
        self.cam = cam
        self.hudObjects = []
        self.hudLayer = Batch()
        self.text = self.create_text_top("")
        self.downVar = None
        self.fps = clock.ClockDisplay()
        
  
    def draw(self):
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        #self.text.draw()
        self.fps.draw()
        self.text = self.create_text_top(self.downVar)
        self.text.draw()
        self.hudLayer.draw()


    def create_text_top(self, text):
        helv = font.load('Helvetica', self.win.width / 15.0)
        text = font.Text(
            helv,
            str( text),
            x=self.win.width / 2,
            y=self.win.height / 10,
            halign=font.Text.CENTER,
            valign=font.Text.CENTER,
            color=(1, 1, 1, 0.5),
        )
        return text 
    
    def addComponent(self,component):
        self.hudObjects.append(component)
        component._set_batch(self.hudLayer)
        
    def on_mouse_motion(self, x, y, dx, dy):    
        self.mousePos = (x,y)        
        

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        self.mousePos = (x,y)     

    def on_mouse_press(self, x, y, button, modifiers):
        pass

    def on_mouse_scroll(self,x, y, scroll_x, scroll_y):
        pass